package com.d3works.apps.base.service.imports;

import com.d3works.apps.base.db.ImportConfiguration;
import com.d3works.apps.base.db.ImportHistory;
import com.d3works.apps.base.db.repo.ImportConfigurationRepository;
import com.d3works.apps.base.service.imports.importer.FactoryImporter;
import com.d3works.exception.D3worksException;
import com.google.inject.Inject;
import java.io.IOException;
import java.util.Map;

public class ImportService {

  @Inject private FactoryImporter factoryImporter;

  @Inject private ImportConfigurationRepository importConfigRepo;

  public ImportHistory run(ImportConfiguration configuration) throws D3worksException, IOException {

    return factoryImporter.createImporter(importConfigRepo.find(configuration.getId())).run();
  }

  public ImportHistory run(ImportConfiguration configuration, Map<String, Object> config)
      throws D3worksException, IOException {

    return factoryImporter.createImporter(importConfigRepo.find(configuration.getId())).run(config);
  }
}
